import sys
import sqlite3
import musicbrainzngs as mb
from utils import dbconn

# Discs from multidisc releases are often not associated with the 
# same MB release. This script shows some of these disc records.

# The problem lies with how we were querying the musicbrainz service
# with the old python library. I also didn't realise before that different
# discs could share the same release.

conn = dbconn()
cursor = conn.cursor()

print "list of duplicate releases...."
# There should be one release record for multi-disc titles.
# List the releases with duplicate names.
duplicate_releases = cursor.execute(
	"SELECT DISTINCT r1.id, r1.title, r1.artist"
	" FROM mbrelease AS r1 INNER JOIN"
	"  mbrelease AS r2 ON "
	"   (r1.id != r2.id and r1.title = r2.title);"
	)
print "\n".join(str(t) for t in duplicate_releases) 
# Find releases with no discnumbers==1.
duplicate_releases = cursor.execute(
	"""select release, path 
	from disc 
	group by num, release 
	having min(num)>1;
	""") 
print "\n".join(str(t) for t in duplicate_releases) 

## TODO: Display some useful information to help resolve the situation
